package com.alex.controller.Import_Reference;

import com.alex.controller.System.AliClientToolNoStreamJson;
import com.alex.controller.System.entity.ChatEntity;
import com.alex.sevice.StaticService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RequestMapping("/reference")
@Tag(name = "参文速查_程智睿")
@RestController
@SuppressWarnings("all")
public class Import_Reference_Controller {
    @Autowired
    private AliClientToolNoStreamJson aliClientToolNoStreamJson;

    @Resource
    StaticService staticService;

    @Operation(summary = "参文速查,请输入您的观点", description = "接口以stream流式返回,参考各大 AI 聊天界面效果,返回结果为")
    @GetMapping("/reference")
    public void chat(@Parameter(name = "content", description = "要输入的内容", example = "吸烟有害健康", required = true) String content, @Parameter(name = "user", description = "用户的登录 ID", example = "2", required = true) String user, HttpServletResponse response) throws IOException {
        System.out.println("用户提问的内容是:" + content);
        List<ChatEntity> list = new ArrayList<>();
        list.add(new ChatEntity("system", "任务说明： 请根据用户给定的观点提取其中的关键词,生成十个对应研究观点的关键词词组或短语,不少于三个单词,这些检索词须为英文，并同时提供它们的中文翻译。请按照以下JSON格式返回\n[{\"en\":\"cardiovascular health aerobic exercise\",\"cn\":\"心血管健康有氧运动\"},{\"en\":\"aerobic exercise blood pressure\",\"cn\":\"有氧运动时的血压\"},{\"en\":\"physical activity blood pressure control\",\"cn\":\"身体活动，血压控制\"}]\n "));
        list.add(new ChatEntity("user", content));
        String send = aliClientToolNoStreamJson.send(list);
        staticService.insStat(content,"参文速查");
        aliClientToolNoStreamJson.sendToClint(response, send);
    }
}
